package com.study.vo.order;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 订单确认页需要的数据
 */
public class OrderConfirmVo implements Serializable {
    private static final long serialVersionUID = 1L;
    /**
     * 收货地址
     */
    @Setter
    @Getter
    List<MemberAddressVo> address;
    /**
     * 订单防止重复
     */
    @Setter
    @Getter
    String orderToken;

    /**
     * 所有选中的购物项
     */
    @Setter
    @Getter
    List<OrderItemVo> items;

    /**
     * 优惠券
     */
    private Integer integration;

    /**
     * 订单总额
     */
    Map<Long, Boolean> stocks;

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null && !items.isEmpty()) {
            for (OrderItemVo item : items) {
                sum = sum.add(item.getPrice().multiply(new BigDecimal(item.getCount().toString())));
            }
        }
        return sum;
    }

    /**
     * 应付金额
     */

    public BigDecimal getPayPrice() {
        BigDecimal sum = new BigDecimal("0");
        if (items != null && !items.isEmpty()) {
            for (OrderItemVo item : items) {
                sum = sum.add(item.getPrice().multiply(new BigDecimal(item.getCount().toString())));
            }
        }
        return sum;
    }
}


